/*
 * HttpRequest.h
 *
 *  Created on: Jul 10, 2024
 *      Author: root
 */

#ifndef BSP_HTTP_HTTPREQUEST_H_
#define BSP_HTTP_HTTPREQUEST_H_
#include "basic_header.h"

namespace bsp {

class HttpRequest {
private:
	std::string methd;
	std::string version;
	std::string path;
	std::unordered_map<std::string, std::string> header;
	std::unordered_map<std::string, std::string> body;

	std::string getLine(std::string &str, size_t start);
	bool parseRequestURL(std::string &line);
	bool parseHeader(std::string &line);
	bool parseBody(std::string &line);

	std::string decode(std::string &val);

public:
	HttpRequest();
	virtual ~HttpRequest();

	bool parseBuffer(std::string &buf, int *err);

	void print();

	bool isKeepAlive();
	std::string getPost(std::string key);
	std::string getHeader(std::string key);

	std::string getPath() {
		return path;
	}

	static void test1();
};

} /* namespace bsp */

#endif /* BSP_HTTP_HTTPREQUEST_H_ */
